#include <Windows.h>
#include "lowlevel_hooks.h"

using namespace std;


UINT_PTR hooks::hook_create( hookType type, LRESULT (CALLBACK *hkFct)(INT, WPARAM, LPARAM) )
{
    INT hkType       = 0;
    UINT_PTR fresult = NULL;
    HINSTANCE hinst  = GetModuleHandle(NULL);

    switch(type)
    {
        case HOOK_KEYBOARD:
            hkType = WH_KEYBOARD_LL;
            break;
        case HOOK_MOUSE:
            hkType = WH_MOUSE_LL;
            break;
        default:
        {
            return fresult;
        }
    }    
    
    HHOOK hkLowLevel = SetWindowsHookEx(WH_KEYBOARD_LL, (*hkFct), hinst, 0);
    fresult = (UINT_PTR)hkLowLevel;

    return fresult;
}


FunctionSuccesFailure hooks::hook_destroy(UINT_PTR hkHookRaw)
{
    HHOOK hkLowLevel = (HHOOK)hkHookRaw;

    if( UnhookWindowsHookEx(hkLowLevel) != 0)
        return FUNCTION_SUCCESS;
    return FUNCTION_FAILURE;
}

